﻿using TOUR.SZHOME.Attributes;
using System.Web.Mvc;
using TOUR.SZHOME.BLL;
using TOUR.SZHOME.Entity;

namespace tour.szhome.manage.area.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        LoginBLL _loginbll = new LoginBLL();

        /// <summary>
        /// 后台首页视图
        /// </summary>
        /// <returns></returns>
        [SelfOnly]
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 404
        /// </summary>
        /// <returns></returns>
        public ActionResult NotFound() 
        {
            return View();
        }

        /// <summary>
        /// 修改密码视图
        /// </summary>
        /// <returns></returns>
        [SelfOnly]
        public ActionResult ChangePwd() 
        {
            return View();
        }

        /// <summary>
        /// 异步修改密码
        /// </summary>
        /// <param name="user"></param>
        /// <param name="oldpwd"></param>
        /// <param name="newpwd"></param>
        /// <returns></returns>
        [SelfOnly]
        public ActionResult JsonChangePwd(LoginEntity user,string oldpwd = "", string newpwd = "") 
        {
            LoginEntity model = _loginbll.GetModelByName(user.userName); // 先拿到实体
            if (model.userPassword != oldpwd)
            {
                return Json(new { code = 1, msg = "原始密码错误" });
            }
            else
            {
                return Json(_loginbll.ChangePwd(user.userID, newpwd));
            } 
        }
    }
}
